import os
import sys
import numpy as np

loss = 1e-3 # 容忍偏差，一般fp16要求绝对误差和相对误差均不超过千分之一
minimum = 10e-10

def verify_result(real_result, golden):
    real_result = np.fromfile(real_result, dtype=np.float32) # 从bin文件读取实际运算结果
    golden = np.fromfile(golden, dtype=np.float32) # 从bin文件读取预期运算结果
    if not np.allclose(real_result, golden, atol=loss, rtol=loss):
        print("[ERROR] result error")
        print(f"Expected {golden}, Shape {golden.shape}, Got {real_result}, Shape {real_result.shape}")
        # Disable ommission
        with np.printoptions(threshold=np.inf):
            print(f"Absolute error: {np.abs(golden - real_result)}")
        return False
    print("test pass")
    return True

if __name__ == '__main__':
    verify_result(sys.argv[1],sys.argv[2])
